package com.gosuncn.zfysdk.demo.base;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.databinding.ViewDataBinding;
import androidx.navigation.NavController;
import androidx.navigation.NavDestination;
import androidx.navigation.Navigation;
import androidx.navigation.fragment.NavHostFragment;

import com.gosuncn.zfysdk.demo.R;
import com.gosuncn.zfysdk.demo.ui.MainActivity;
import com.wzq.mvvmsmart.base.BaseActivityMVVM;
import com.wzq.mvvmsmart.base.BaseViewModelMVVM;

public abstract class BaseActivity<V extends ViewDataBinding, VM extends BaseViewModelMVVM> extends BaseActivityMVVM<V, VM> {
    public final String TAG = getClass().getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initToolbar();
    }

    public void initToolbar() {
        Toolbar toolbar = (Toolbar)this.getWindow().getDecorView().findViewById(R.id.toolbar);
        if(toolbar != null) {
            this.setSupportActionBar(toolbar);
        }

        NavController navController = Navigation.findNavController(this, R.id.fragment);
        if(navController != null) {
            navController.addOnDestinationChangedListener(new NavController.OnDestinationChangedListener() {
                @Override
                public void onDestinationChanged(@NonNull NavController controller, @NonNull NavDestination destination, @Nullable Bundle arguments) {
//                KLog.d(TAG, "onDestinationChanged getNavigatorName:" + destination.getNavigatorName());
//                KLog.d(TAG, "onDestinationChanged getLabel:" + destination.getLabel());
                    ActionBar actionBar = BaseActivity.this.getSupportActionBar();
                    if (actionBar != null) {
                        actionBar.setTitle(destination.getLabel());
                    }
                }
            });
        }
    }
}